#ifndef MULTISCREEN_H
#define MULTISCREEN_H

#include <QMainWindow>
#include <QObject>
#include <QWidget>
#include <QTimer>
#include <QtHttpServer/QHttpServer>
#include <QTcpSocket>
#include <QJsonObject>
#include <QJsonDocument>

enum CALL_TYPE{
    CALL_IDLE,
    CALL_INCOMING,
    CALL_RING,
    CALL_ACTIVE,
    CALL_HELD,
    CALL_TERMINATED
};

class MainWindow;

class MultiScreen :public QObject {
    Q_OBJECT
public:
    MultiScreen();
    ~MultiScreen();
static std::unique_ptr<MultiScreen>& getInstance();
    bool startHttpServer();
    bool connectHuServer();
    bool playMusic();
    bool callOut();
    bool nextMusic();
signals:
    void CallingTimerSignal(int status, const QString &message);
    void MusicTimerSignal(bool status, bool ConnectedStatus, const QString &message);

private:
    static std::unique_ptr<MultiScreen>             multiScreenInstance;

    QHttpServer *httpServer = nullptr;
    bool isServerRunning = false;

    QTcpSocket socket;
    bool isConnected = false;
    bool isPlaying = false;
    QTimer *timerMusic = nullptr;
    int MusicSeconds = 0;
    int MusicSecondsTotal = 0;
    void MusicTimerUpdater();
    QJsonObject MusicjsonObject;
    int MusicIndex = 0;
    const int MusicNumberMax = 2;
    void sendPackets(int number, int status);

    bool isCalling  = false;
    QTimer *timerCalling = nullptr;
    int elapsedSeconds = 0;
    void CallingTimerUpdater();
    void CallingDataSend(QJsonObject& json);
    QJsonObject CalljsonData;
    enum CALL_TYPE CallStatus = CALL_IDLE;
};



#endif // MULTISCREEN_H
